package com.windward.vii.dao.mapper;

import com.windward.vii.dao.entity.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface GoodsMapper {
    @Delete({
        "delete from goods",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into goods (id, sn, name, ",
        "price, coin, icon, ",
        "status, terminal_type, ",
        "create_time, update_time)",
        "values (#{id,jdbcType=BIGINT}, #{sn,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, ",
        "#{price,jdbcType=INTEGER}, #{coin,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR}, ",
        "#{status,jdbcType=TINYINT}, #{terminalType,jdbcType=TINYINT}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})"
    })
    int insert(Goods record);

    int insertSelective(Goods record);

    @Select({
        "select",
        "id, sn, name, price, coin, icon, status, terminal_type, create_time, update_time",
        "from goods",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    Goods selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Goods record);

    @Update({
        "update goods",
        "set sn = #{sn,jdbcType=VARCHAR},",
          "name = #{name,jdbcType=VARCHAR},",
          "price = #{price,jdbcType=INTEGER},",
          "coin = #{coin,jdbcType=INTEGER},",
          "icon = #{icon,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=TINYINT},",
          "terminal_type = #{terminalType,jdbcType=TINYINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Goods record);

    /***********以下为自定义方法************************/

    @Select({
            "select id, sn, name, price, coin, icon",
            "from goods",
            "where terminal_type = #{terminalType,jdbcType=TINYINT} and status = 1 order by id"
    })
    @ResultMap("BaseResultMap")
    List<Goods> getGoodsList(Integer terminalType);

    @Select({
            "select *",
            "from goods",
            "where sn = #{sn,jdbcType=VARCHAR}"
    })
    @ResultMap("BaseResultMap")
    Goods getBySn(String sn);
}